//
//  MSPSettingsModule.m
//  msp
//
//  Created by James Callender on Sat Jun 19 2004.
//  Copyright (c) 2004 James Callender. All rights reserved.
//

#import "MSPSettingsModule.h"


@implementation MSPSettingsModule

- (id)init
{
    if (self = [super init]) {
        [NSBundle loadNibNamed:@"MSPSettingsView" owner:self];
    }
    
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)awakeFromNib
{
    
}

- (NSString *)settingsDisplayName
{
    return @"MSP";
}

- (NSImage *)settingsDisplayIcon
{
    return [[[NSImage alloc] initWithContentsOfFile:
	[[NSBundle bundleForClass:[MSPSettingsModule class]] pathForResource:@"MSPIcon" ofType:@"tiff"]]
	    autorelease];
}

- (NSView *)settingsView
{
    return oSettingsView;
}

- (NSSize)size
{
    return NSMakeSize(519, 152);
}

- (id)world
{
    return currentWorld;
}

- (void)updateForWorld:(id)world
{
    if (world != currentWorld) {
	[self willChangeValueForKey:@"world"];
	currentWorld = world;
	[self didChangeValueForKey:@"world"];
    }
}

- (NSDictionary *)defaultWorldProperties
{
    return [NSDictionary dictionaryWithObject:
	[NSMutableDictionary dictionaryWithObjectsAndKeys:
	    [NSNumber numberWithBool:YES], @"filterMSPCommands",
	    [NSNumber numberWithBool:YES], @"enableMSP",
	    [NSNumber numberWithBool:YES], @"downloadAutomatically",
	    [NSNumber numberWithBool:YES], @"allowInlineMatches",
	    @"~/Library/Application Support/Cantrip/Sounds", @"soundsFolderPath",
	    nil] forKey:@"msp"];
}

#pragma mark Interface Actions

- (IBAction)selectSoundsFolderAction:(id)sender
{
    NSOpenPanel *panel = [NSOpenPanel openPanel];
    [panel setCanChooseDirectories:YES];
    [panel setCanChooseFiles:NO];
    [panel setAllowsMultipleSelection:NO];
    if ([panel runModalForTypes:nil]) {
	[currentWorld setValue:[[panel filenames] objectAtIndex:0] forKeyPath:@"data.msp.soundsFolderPath"];
    }
}

@end
